package com.lcdpg.lcdp.auth.contorller;


import com.lcdpg.lcdp.auth.domain.LoginRequest;
import com.lcdpg.lcdp.auth.service.AuthService;
import com.lcdpg.lcdp.common.core.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.bind.annotation.*;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName AuthLoginContorller.java
 * @Description TODO
 * @createTime 2025年05月22日 21:05:00
 */
@RestController
@RequestMapping("/auth")
@Tag(name = "用户服务")
public class AuthLoginContorller {

    @Autowired
    private AuthService  authService;

    @PostMapping("/login")

    @Operation(
            summary = "登录接口",
            description = "通过用户名密码获取 JWT Token"
    )
    public R<String> login(@RequestBody @Valid LoginRequest request) {
        try {
            String token = authService.login(request);
            return R.ok(token);
        } catch (AuthenticationException e) {
            return R.fail("登录失败: " + e.getMessage());
        }
    }

    @GetMapping("/test")
    public String test(){
        return "Hello Word";

    }
}
